//
//  NSDictionary+Commons.m
//  Categorys
//
//  Created by taihankeji on 2017/5/17.
//  Copyright © 2017年 taihankeji. All rights reserved.
//

#import "NSDictionary+Commons.h"

@implementation NSDictionary (Commons)


- (NSString *)dictonaryToJsonString {
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:&error];
    
    if (jsonData == nil) {
#ifdef DEBUG
        NSLog(@"fail to get JSON from dictionary: %@, error: %@", self, error);
#endif
        return nil;
    }
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    return jsonString;
}

@end
